package cn.edu.neusoft.maxingxin231.yuejian06.Activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.AttListAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.PostAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.PostBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.PostModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class PostListActivity extends BaseActivity {
    RecyclerView recyclerview;
    ImageButton bt_back;
    private List<PostBean> items;
    PostModel postModel;
    private String user_id,post_id,post_tiel,user_name,post_img,see_num;
    PostAdapter postAdapter;
    private RecyclerView.LayoutManager layoutManager;
    ListListener<PostBean> postBeanListListener = new ListListener<PostBean>() {
        @Override
        public void onResponse(List<PostBean> list) {
            items = list;
            postAdapter.setList(list);


        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    void initView() {
        setLayout_file(R.layout.activity_postlist);
        recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
        LinearLayoutManager layoutLayoutManager=new LinearLayoutManager(PostListActivity.this);
        recyclerview.setLayoutManager(layoutLayoutManager);
        layoutLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        bt_back = (ImageButton)findViewById(R.id.bt_back);
        post_id = getIntent().getStringExtra("post_id");
        post_tiel = getIntent().getStringExtra("post_title");
        post_img = getIntent().getStringExtra("post_img");
        see_num = getIntent().getStringExtra("see_num");
        user_id = getUser_id();
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        recyclerview.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerview.setHasFixedSize(true);
        //创建并设置Adapter
        //list = getData();
        postAdapter = new PostAdapter(PostListActivity.this,items,R.layout.post_card);
        postAdapter.setList(items);
        recyclerview.setAdapter(postAdapter);
    }

    @Override
    void initEvent() {
        bt_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        PostModel postModel = new PostModel();
        postModel.getUserPostList(getUser_id(),postBeanListListener);
    }

    @Override
    void initData() {

    }

//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_postlist);
//    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
